package com.qixin.modules.eaBasic.util;

import com.qixin.modules.ea.entity.EaSysDictItem;
import com.qixin.modules.ea.mapper.EaSysDepartMapper;
import com.qixin.modules.ea.mapper.EaSysDictItemMapper;
import com.qixin.modules.ea.mapper.EaSysUserMapper;
import com.qixin.modules.ea.vo.EaSysDepart;
import com.qixin.modules.ea.vo.EaSysUser;
import com.qixin.modules.ea.vo.EaSysUserDepart;
import com.qixin.modules.eaBasic.entity.EaRegion;
import com.qixin.modules.eaBasic.entity.EaTitle;
import com.qixin.modules.eaBasic.mapper.EaRegionMapper;
import com.qixin.modules.eaBasic.mapper.EaTitleMapper;
import org.jeecg.common.util.EmptyUtil;
import org.jeecg.modules.nc.entity.NcOrg;
import org.jeecg.modules.nc.entity.NcPersonnel;
import org.jeecg.modules.nc.mapper.NcOrgMapper;
import org.jeecg.modules.nc.mapper.NcPersonnelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

/**
 * @Author:wly
 * @Date:2021/9/23
 * @Describtion: 传入ID转换成Name
 */
@Service
public class ChangeIdToNameUtil {
    @Autowired
    private EaSysUserMapper eaSysUserMapper;
    @Autowired
    private EaSysDepartMapper eaSysDepartMapper;
    @Autowired
    private EaRegionMapper eaRegionMapper;
    @Autowired
    private EaSysDictItemMapper eaSysDictItemMapper;
    @Autowired
    private EaTitleMapper eaTitleMapper;
    @Autowired
    private NcOrgMapper ncOrgMapper;
    @Autowired
    private NcPersonnelMapper ncPersonnelMapper;

    public String getNameById(String id){//传入用户id
        if(id == null || id.equals("")){
            return "";
        }
        EaSysUser sysUser = eaSysUserMapper.selectById(id);
        String name = sysUser.getRealname();   //获取用户姓名
        return name;
    }

    public String getPsnNameById(String id){// 传入人员编码id
        if(id == null || id.equals("")){
            return "";
        }
        NcPersonnel ncPersonnel = ncPersonnelMapper.selectById(id);
        String name = ncPersonnel.getName();
        return name;
    }

    public String getNameByUsername(String username){//传入用户账号
        if(username == null || username.equals("")){
            return "";
        }
        Map<String,Object> paramsMap = new HashMap<String,Object>();
        paramsMap.put("userid",username);
        List<EaSysUser> sysUserList = eaSysUserMapper.selectByMap(paramsMap);
        String name = "";
        if(sysUserList.size() > 0){
            name = sysUserList.get(0).getRealname();   //获取用户姓名
        }
        return name;
    }

    public String getNameByDepartId(String id){//传入部门id
        if(id == null || id.equals("")){
            return "";
        }
        Map<String,Object> paramsMap = new HashMap<String,Object>();
        paramsMap.put("id",id);
        List<EaSysDepart> eaSysDepartList = eaSysDepartMapper.selectByMap(paramsMap);
        String name = "";
        if(eaSysDepartList.size() > 0){
           name = eaSysDepartList.get(0).getDepartName();   //获取部门名称
        }
        return name;
    }

    public String getIdByKindName(String kindName){//传入Kindname,返回id
        if(EmptyUtil.checkNull(kindName).equals("")){
            return "";
        }
        if(kindName.equals("交通")){
            return "2";
        }else if(kindName.equals("住宿")){
            return "3";
        }else if(kindName.equals("餐饮")){
            return "1";
        }else if(kindName.equals("通讯")){
            return "6";
        }else{
            return "7";
        }
    }

    public String getIdByRegionName(String regionName){//传入地区名称,返回id
        if(EmptyUtil.checkNull(regionName).equals("")){
            return "";
        }
        Map<String,Object> params = new HashMap<String,Object>();
        params.put("name",regionName);
        List<EaRegion> eaRegionList = eaRegionMapper.selectByMap(params);
        String id = "";
        if(eaRegionList.size() > 0){
            EaRegion eaRegion = eaRegionList.get(0);
            id = EmptyUtil.checkNull(eaRegion.getId());
        }

        return id;
    }

    public String getIdByTrainName(String seatName,String trainNumber){//传入火车座位名称,火车车次,返回id
        if(EmptyUtil.checkNull(trainNumber).equals("") || EmptyUtil.checkNull(seatName).equals("")){
            return "";
        }
        String dictId = "";     //字典id
        if(trainNumber.contains("G")){  //高铁
            dictId = "1415880295613206530";
        }else if(trainNumber.contains("D") | trainNumber.contains("C")){   //动车
            dictId = "1415879800538533889";
        }else{  //普通列车
            dictId = "1415879268965027841";
        }

        Map<String,Object> params = new HashMap<String,Object>();
        params.put("dict_id",dictId);
        params.put("item_text",seatName);
        List<EaSysDictItem> eaSysDictItemList = eaSysDictItemMapper.selectByMap(params);
        String id = "";   //字典表id
        if(eaSysDictItemList.size() > 0){
            EaSysDictItem eaSysDictItem = eaSysDictItemList.get(0);
            id = eaSysDictItem.getId();
        }

        return id;
    }

    public String getIdByPlaneName(String seatName,String internationalFlag){//传入飞机座位名称,是否国内航班D,返回id
        if(EmptyUtil.checkNull(seatName).equals("")){
            return "";
        }
        String dictId = "";     //字典id
        if(internationalFlag.contains("D")){  //国内航班
            dictId = "1415954189455986689";
        }else{                                //国外航班
            dictId = "1415953783157952514";
        }

        Map<String,Object> params = new HashMap<String,Object>();
        params.put("dict_id",dictId);
        params.put("item_text",seatName);
        List<EaSysDictItem> eaSysDictItemList = eaSysDictItemMapper.selectByMap(params);
        String id = "";   //字典表id
        if(eaSysDictItemList.size() > 0){
            EaSysDictItem eaSysDictItem = eaSysDictItemList.get(0);
            id = eaSysDictItem.getId();
        }

        return id;
    }

    public String getNameByTitleId(String titleId){//传入职务id,返回职务名称
        if(EmptyUtil.checkNull(titleId).equals("")){
            return "";
        }
        Map<String,Object> params = new HashMap<String,Object>();
        params.put("id",titleId);
        List<EaTitle> eaTitleList = eaTitleMapper.selectByMap(params);
        String name = "";
        if(eaTitleList.size() > 0){
            EaTitle eaTitle = eaTitleList.get(0);
            name = EmptyUtil.checkNull(eaTitle.getName());
        }

        return name;
    }

    public String getNameByTypeId(String type){//传入发票类型id,返回发票类型名称:所有
        if(EmptyUtil.checkNull(type).equals("")){
            return "";
        }
        Map<String,Object> params = new HashMap<String,Object>();
        params.put("item_value",type);
        params.put("dict_id","1411894489202585601");
        List<EaSysDictItem> eaSysDictItemList = eaSysDictItemMapper.selectByMap(params);
        String name = "";
        if(eaSysDictItemList.size() > 0){
            EaSysDictItem eaSysDictItem = eaSysDictItemList.get(0);
            name = EmptyUtil.checkNull(eaSysDictItem.getItemText());
        }

        return name;
    }

    public String getEffectiveNameByTypeId(String type){//传入发票类型id,返回发票类型名称:启用
        if(EmptyUtil.checkNull(type).equals("")){
            return "";
        }
        Map<String,Object> params = new HashMap<String,Object>();
        params.put("item_value",type);
        params.put("dict_id","1411894489202585601");
        params.put("status","1");
        List<EaSysDictItem> eaSysDictItemList = eaSysDictItemMapper.selectByMap(params);
        String name = "";
        if(eaSysDictItemList.size() > 0){
            EaSysDictItem eaSysDictItem = eaSysDictItemList.get(0);
            name = EmptyUtil.checkNull(eaSysDictItem.getItemText());
        }

        return name;
    }
    
    // 通过组织id查询组织名称
    public String getCompanyNameById(String id){
        if(EmptyUtil.checkNull(id).equals("")){
            return "";
        }
        NcOrg ncOrg = ncOrgMapper.queryOne(id);
        String name = "";
        if(ncOrg != null){
            name = ncOrg.getName();
        }
        return name;
    }

    // 通过出差类型id查询名称
    public String getTypeIdById(Integer type){
        if(type == null){
            return "";
        }
        Map<String,Object> params = new HashMap<String,Object>();
        params.put("item_value",type);
        params.put("dict_id","1417396005166497794");
        params.put("status","1");
        List<EaSysDictItem> eaSysDictItemList = eaSysDictItemMapper.selectByMap(params);
        String name = "";
        if(eaSysDictItemList.size() > 0){
            EaSysDictItem eaSysDictItem = eaSysDictItemList.get(0);
            name = EmptyUtil.checkNull(eaSysDictItem.getItemText());
        }
        return name;
    }

}
